package com.briup.web;

import com.briup.bean.CallLog;
import com.briup.bean.CallPer;
import com.briup.bean.Consume;
import com.briup.bean.Plan;
import com.briup.service.ICalllogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @author adam
 * @date 2023/2/27
 */
@RestController
public class EChartsController {
    @Autowired
    ICalllogService calllogService;

    @PostMapping("getData")
    public Map<String, Object> getData(String tel, String callTime) {
        HashMap<String, Object> map = new HashMap<>();
        List<CallLog> logs = calllogService.queryMonthDatas(tel, callTime);
        Plan plan = calllogService.queryCurrRemainder(tel, callTime);
        CallPer callPer = calllogService.queryPerRemainder(tel, callTime);
        List<Consume> list = calllogService.queryMonthConsume(tel, callTime);
        Consume consume = calllogService.queryYearConsume(tel, callTime);
        ArrayList<Object> oPlans = new ArrayList<>();
        ArrayList<Object> nPlans = new ArrayList<>();
        ArrayList<Object> consumes = new ArrayList<>();
        ArrayList<Object> fluxs = new ArrayList<>();
        ArrayList<Object> calls = new ArrayList<>();
        ArrayList<Object> messages = new ArrayList<>();

        for (CallLog log : logs) {
            oPlans.add(String.valueOf(log.getOPlan()));
            nPlans.add(String.valueOf(log.getNPlan()));
        }
        for (Consume consume1 : list) {
            consumes.add(String.valueOf(consume1.getNum()));
            fluxs.add(consume1.getFlux());
            calls.add(consume1.getCall());
            messages.add(consume1.getMessage());

        }
        map.put("oPlan", oPlans);
        map.put("nPlan", nPlans);
        map.put("consumes", consumes);
        map.put("fluxs",fluxs);
        map.put("messages",messages);
        map.put("calls",calls);
        return map;
    }

}
